<template>
  <div id="app">
    <el-container v-if="isLoggedIn">
      
      <el-main>
        <router-view></router-view>
      </el-main>
      
    </el-container>
    <router-view v-else></router-view>
  </div>
</template>

<script>
import MessageNotification from '@/components/MessageNotification.vue'

export default {
  components: {
    MessageNotification
  },
  data() {
    return {
      isLoggedIn: false,
      username: ''
    }
  },
  created() {
    // 检查用户是否已登录
    const token = localStorage.getItem('token')
    const username = localStorage.getItem('username')
    if (token && username) {
      this.isLoggedIn = true
      this.username = username
    }
  },
  methods: {
    handleCommand(command) {
      if (command === 'logout') {
        // 清除登录信息
        localStorage.removeItem('token')
        localStorage.removeItem('username')
        localStorage.removeItem('userId')
        this.isLoggedIn = false
        this.$router.push('/login')
      } else if (command === 'profile') {
        this.$router.push('/profile')
      }
    }
  }
}
</script>

<style>
body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
}

#app {
  height: 100%;
}
</style> 